package com.gdziarmaga.webshop.client.model;

import java.util.Date;

import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.gdziarmaga.webshop.core.dao.GenericDaoImpl;
import com.gdziarmaga.webshop.utils.springcontext.AppContext;

@Repository("clientRepo")
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public class ClientDAOImpl extends GenericDaoImpl<Client, Long> implements ClientDAO {
	@Override
	public Client findProductByEmail(String email) {
		return getObjectByCriteria(createDetachedCriteria().add(Restrictions.eq(Client.EMAIL, email)));
	}

	@Override
	public Client findProductByFirst_name(String first_name) {
		return getObjectByCriteria(createDetachedCriteria().add(Restrictions.eq(Client.FIRST_NAME, first_name)));
	}

	@Override
	public Client findProductByLast_name(String last_name) {
		return getObjectByCriteria(createDetachedCriteria().add(Restrictions.eq(Client.LAST_NAME, last_name)));
	}

	@Override
	public Client findProductByPost(String post) {
		return getObjectByCriteria(createDetachedCriteria().add(Restrictions.eq(Client.POST, post)));
	}

	@Override
	public Client findProductByDate_of_birth(Date date_of_birth) {
		return getObjectByCriteria(createDetachedCriteria().add(Restrictions.eq(Client.DATE_OF_BIRTH, date_of_birth)));
	}

	
}
